package com.hyk.learning.loadbalance.loadbalancer;

import com.hyk.learning.dto.RpcRequest;
import com.hyk.learning.loadbalance.AbstractLoadBalance;

import java.util.List;
import java.util.Random;

/**
 * @className: RandomLoadBalance
 * @author: hyk199710
 * @description: Implementation of random load balancing strategy
 * @date: 2024/4/29 23:30
 */
public class RandomLoadBalance extends AbstractLoadBalance {
    @Override
    protected String doSelect(List<String> serviceUrlList, RpcRequest rpcRequest) {
        Random random = new Random();
        return serviceUrlList.get(random.nextInt(serviceUrlList.size()));
    }
}
